package puppy.graph;

import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;

public class AgeAggregator {

	/**
	 * @param args
	 */



	public Hashtable<String,Boolean> ages =new Hashtable<String,Boolean>();
	
	
	public void printAges(){
		
		
		Enumeration<String> keys = ages.keys();
		
		while(keys.hasMoreElements()){
			String key =keys.nextElement();
			System.out.println(key+"\t"+ages.get(key));
			
		}
		
	}
	
	public AgeAggregator(HashSet<String> ages_t){
		
		
		ages.put("kids", false);
		ages.put("kids-teens", false);
		ages.put("kids-teens-mteens", false);
		ages.put("teens", false);
		ages.put("teens-mteens", false);
		ages.put("mteens", false);
		ages.put("adults", false);
		ages.put("kids-entertainment", false);
		ages.put("kids-plus", false);
		ages.put("dmoz_plus", false);
		
		Iterator<String> iter = ages_t.iterator();
		
		
		while(iter.hasNext()){
			
			String a= iter.next();
			
			if(ages.containsKey(a)){
			
				ages.put(a,true);
			}
			
		}
	}
	
	


	public boolean isAgeValid(String age){
		Boolean temp = ages.get(age.trim());
		//System.out.println(temp + "\t"+ age + "\t" + ages.get(age));
	
		if(temp==true) 
		{
			
			return true;
		}	


		return false;
	}



	public double getAggregate(Hashtable<String,? extends Number> h){


		double total =0.0f;

		if(ages.get("kids")==true && h.containsKey("kids")){
			Number n = (Number) h.get("kids");

			total = total+ n.doubleValue();

		}


		if(ages.get("teens")==true && h.containsKey("teens")){

			Number n = (Number) h.get("teens");
			total = total+ n.doubleValue();
		}

		if(ages.get("mteens")==true && h.containsKey("mteens")){
			Number n = (Number) h.get("mteens");
			total = total+ n.doubleValue();

		}


		if(ages.get("adults")==true&& h.containsKey("adults")){

			Number n = (Number) h.get("adults");
			total = total+ n.doubleValue();
		}

		//intemediates

		//System.out.println("POr entrar kids teens "+  h );
		if(ages.get("kids-teens")==true && h.containsKey("kids-teens")){
			//	System.out.println("Entrooo kids teens"  );
			Number n = (Number) h.get("kids-teens");
			total = total+ n.doubleValue();
		}

		if(ages.get("teens-mteens")==true&& h.containsKey("teens-mteens")){
			Number n = (Number) h.get("teens-mteens");
			total = total+ n.doubleValue();

		}


		if(ages.get("kids-teens-mteens")==true&& h.containsKey("kids-teens-mteens")){

			Number n = (Number) h.get("kids-teens-mteens");
			total = total+ n.doubleValue();
		}

		if(ages.get("kids-entertainment")==true&& h.containsKey("kids-entertainment")){

			Number n = (Number) h.get("kids-entertainment");
			total = total+ n.doubleValue();
		}
		if(ages.get("kids-plus")==true&& h.containsKey("kids-plus")){

			Number n = (Number) h.get("kids-plus");
			total = total+ n.doubleValue();
		}

		
		if(ages.get("dmoz_plus")==true&& h.containsKey("dmoz_plus")){

			Number n = (Number) h.get("dmoz_plus");
			total = total+ n.doubleValue();
		}


		return total;

	}


	public static String decodeAge(short n){



		if(n==0){


			return "kids";
		}


		if(n==1){


			return "kids-teens";
		}




		if(n==2){


			return "teens";
		}



		if(n==3){


			return "teens-mteens";
		}




		if(n==4){


			return "mteens";
		}


		if(n==5){


			return "kids-teens-mteens";
		}

		if(n==6)
			return "adults";


		return "error";
	}




	public static Short encodeAge(String n){



		if(n.equals("kids")){


			return 0;
		}


		if(n.equals("kids-teens")){


			return 1;
		}




		if(n.equals("teens")){


			return 2;
		}



		if(n.equals("teens-mteens")){


			return 3;
		}




		if(n.equals("mteens")){


			return 4;
		}


		if(n.equals("kids-teens-mteens")){


			return 5;
		}

		if(n.equals("adults"))
			return 6;


		return -1;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub


		Number n = new Integer(3);

		Integer x = 3;

		n =   x;
		
		System.out.println(n);

	}

}
